home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-07 | 2.8 KB | 123 lines | [TEXT/MWII] |
- // Copyright © 1989-1990 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __UGRAPH__
- #include "UGraph.h"
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void
- TGraph::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
- {
- GraphStructPtr aGraphStructPtr;
- Rect aRect;
-
- inherited::IRes(itsDocument, itsSuperView, itsParams);
- aGraphStructPtr = DoGraphInit(kBar);
- fData = aGraphStructPtr;
- aRect = gZeroRect;
- if (Focus())
- GetQDExtent(&aRect);
- SetGraphRect(aRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void
- TGraph::SetGraphRect(Rect graphRect)
- {
- DoGraphSetGraphRect(graphRect.top, graphRect.left, graphRect.bottom, graphRect.right, fData);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TGraph::SetPoint( short which, long value )
- {
- DoGraphSetPoint(which, value, fData);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal short
- TGraph::GetNumPoints()
- {
- return DoGraphGetNumPoints(fData);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TGraph::ComputeBars(Boolean redraw)
- {
- DoGraphComputeBars(fData);
- if (redraw)
- ForceRedraw();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TGraph::GetCoordinateRange(Rect *coordRange)
- {
- coordRange->top = DoGraphGetYMax(fData);
- coordRange->bottom = DoGraphGetYMin(fData);
- coordRange->left = 0;
- coordRange->right = GetNumPoints();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void
- TGraph::Draw(Rect *area)
- {
- Rect qdRect;
- Rect dstRect;
- Rect barRect;
- short numPoints;
-
- GetQDExtent(&qdRect);
-
- // draw Y-axis
- dstRect = qdRect;
- dstRect.right = dstRect.left + 1;
- if (SectRect(&dstRect, area, &dstRect))
- FrameRect(&dstRect);
-
- // draw X-axis
- dstRect = qdRect;
- dstRect.top = dstRect.bottom - 1;
- if (SectRect(&dstRect, area, &dstRect))
- FrameRect(&dstRect);
-
- // draw the bars
- numPoints = GetNumPoints();
- for (short i = 1; i <= numPoints; i++) {
- DoGraphGetBar(i, &barRect.top, &barRect.left, &barRect.bottom, &barRect.right, fData);
- if (SectRect(&barRect, area, &dstRect)) {
- ForeColor(redColor);
- PaintRect(&barRect);
- ForeColor(blackColor);
- FrameRect(&barRect);
- }
- }
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AClose
-
- pascal void
- TGraph::Free()
- {
- fData = DoGraphDispose(fData);
- inherited::Free();
- }